package top.kaoshanji.p2ch16a.v1;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * author kaoshanji
 * ^_^
 * create time 2025/2/14 18:58
 */
public class ShopMain {

    private static final Logger logger = LogManager.getLogger(ShopMain.class);

    public static void main(String[] args) {
        logger.info("...代码清单-p2ch16a-349页a：使用异步API...");

        Shop shop = new Shop("BestShop"); // 商店
        Future<Double> futurePrice = shop.getPriceAsync("my favorite product"); // 商品

        // 执行更多任务，比如查询其他商店
        doSomethingElse();
        // 在计算商品价格的同时

        try {
            double price = futurePrice.get();
            System.out.printf("Price is %.2f%n", price);
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }

    }

    private static void doSomethingElse() {
        System.out.println("Doing something else...");
    }

}
